package net.wwang.blog.dao;

import net.wwang.blog.pojo.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;


public interface UserDao extends JpaRepository<User,String>, JpaSpecificationExecutor<User> {


    User findUserByUsername(String name);

    User findUserByEmail(String email);

    User findUserById(String userId);

    @Query(nativeQuery=true,value="select * from `user`")
    Page<User> getUserList(Pageable pageable);

    @Modifying
    @Query(nativeQuery=true,value = "UPDATE `user` SET `state` = '0' WHERE `id` = ?1")
    int deleteUserByState(String userId);

    @Modifying
    @Query(nativeQuery=true,value="update `user` set `password`=?1 where `email` = ?2")
    int updatePasswordByEmail(String encode, String emailAdress);

    @Modifying
    @Query(nativeQuery=true,value="update `user` set `email`=?1 where `id` = ?2")
    int updateEmailByUserId(String email, String id);
}
